using UnityEngine;

public class PurchaseBallsTab : MonoBehaviour
{
	public GameObject inAppButonPrefab;

	public UITable table;

	public Transform firstObject;

	public UIScrollView view;

	public InAppPurchase.ItemType itemType;

	private int tableRepositionCount;

	protected bool isAligned;

	private void Start()
	{
		Debug.Log("Purchase Tab Started");
		InAppPurchase instance = InAppPurchase.instance;
		int num = 2;
		foreach (InAppPurchase.InAppObject inAppProduct in instance.inAppProducts)
		{
			if (inAppProduct.type == itemType)
			{
				GameObject gameObject = NGUITools.AddChild(table.gameObject, inAppButonPrefab);
				gameObject.SetActive(true);
				gameObject.name = num++.ToString();
				InAppButton component = gameObject.GetComponent<InAppButton>();
				component.Init(inAppProduct);
				if (firstObject == null)
				{
					firstObject = gameObject.transform;
				}
			}
		}
		table.Reposition();
	}

	private void OnEnable()
	{
		tableRepositionCount = 0;
		isAligned = false;
	}

	private void Update()
	{
		if (tableRepositionCount <= 10)
		{
			if (tableRepositionCount == 10)
			{
				table.Reposition();
			}
			if (tableRepositionCount++ == 10 && !isAligned)
			{
				UITools.AlignToTopOnScroll(firstObject.GetComponent<UIWidget>(), view, -10f);
				isAligned = true;
			}
		}
	}
}
